// 检查shared_items表结构的脚本
const mysql = require('mysql2/promise');
require('dotenv').config();

async function checkSharedItemsTable() {
  try {
    // 创建数据库连接
    const connection = await mysql.createConnection({
      host: process.env.DB_HOST || 'localhost',
      user: process.env.DB_USER || 'root',
      password: process.env.DB_PASSWORD || '',
      database: process.env.DB_NAME || 'neighborhood_service'
    });

    console.log('📋 检查shared_items表结构:');
    // 查询表结构
    const [columns] = await connection.execute('DESCRIBE shared_items');
    console.log('字段列表:');
    columns.forEach(col => {
      console.log(`  ${col.Field} (${col.Type}) - ${col.Null === 'YES' ? '可空' : '非空'} - ${col.Key || '无键'}`);
    });

    console.log('\n📋 检查shared_items表数据:');
    // 查询表数据
    const [rows] = await connection.execute('SELECT * FROM shared_items LIMIT 5');
    console.log('数据示例:');
    rows.forEach((row, index) => {
      console.log(`  记录${index + 1}: ${JSON.stringify(row, null, 2)}`);
    });

    await connection.end();
  } catch (error) {
    console.error('检查shared_items表结构时出错:', error);
  }
}

checkSharedItemsTable();